package concurrency;

import java.util.Random;
import java.util.concurrent.TimeUnit;

class CustomerGenerator implements Runnable {
    private CustomerLine mCustomers;

    private static Random sRand = new Random(47);

    public CustomerGenerator(CustomerLine cq) {
        mCustomers = cq;
    }

    @Override
    public void run() {
        try {
            while (!Thread.interrupted()) {
                TimeUnit.MILLISECONDS.sleep(sRand.nextInt(300));
                mCustomers.put(new Customer(sRand.nextInt(1000)));
            }
        } catch (InterruptedException e) {
            System.out.println("CustomerGenerator interrupted");
            // e.printStackTrace();
        }
        System.out.println("CustomerGenerator terminating");
    }
}
